package net.neimeng.luculent.coremodel.base.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import net.neimeng.luculent.coremodel.datamodel.http.PageResult;
import net.neimeng.luculent.coremodel.utils.Logger;

/**
 * Created by jingwenguang on 2018/1/20.
 */

public class BaseFragment extends Fragment {

    private  String TAG = "BaseFragment";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.d(TAG,getClass().getSimpleName());
    }

    //上拉刷新或者下拉加载后的统一处理方法  （暂时先放在这里，后期可以独立到一个类中）
    public <T> void afterRefreshLoadMore(SmartRefreshLayout refreshLayout, PageResult<T> result, BaseQuickAdapter adapter){
        switch (result.getOperateType()){
            case First:
                refreshLayout.setNoMoreData(!result.isHasNext());
                break;
            case Refresh:
                refreshLayout.finishRefresh();
                refreshLayout.setNoMoreData(!result.isHasNext());
                adapter.getData().clear();
                break;
            case LoadMore:
                if(!result.isHasNext()){
                    refreshLayout.finishLoadMoreWithNoMoreData();//完成加载并标记没有更多数据 1.0.4
                }else{
                    refreshLayout.finishLoadMore();
                }
                break;
        }
        adapter.getData().addAll(result.getListData());
        adapter.notifyDataSetChanged();
    }

}
